03. HTTP Requests

HTTP Requests

HTTP request elements

FSND C2 L2 A03 HTTP Request Elements

HTTP request methods

FSND C2 L2 A04 HTTP Request Methods

HTTP Requests

HTTP requests are sent from the client to the server to initiate some operation. In addition to the URL, HTTP requests have other elements to specify the requested resource.

Elements:

  • Method: Defines the operation to be performed
  • Path: The URL of the resource to be fetched, excluding the scheme and host
  • HTTP Version
  • Headers: optional information, success as Accept-Language
  • Body: optional information, usually for methods such as POST and PATCH, which contain the resource being sent to the server

Request Methods

Different request methods indicate different operations to be performed. It's essential to attend to this to correctly format your requests and properly structure an API.

  • GET: ONLY retrieves information for the requested resource of the given URI
  • POST: Send data to the server to create a new resource.
  • PUT: Replaces all of the representation of the target resource with the request data
  • PATCH: Partially modifies the representation of the target resource with the request data
  • DELETE: Removes all of the representation of the resource specified by the URI
  • OPTIONS: Sends the communication options for the requested resource

QUIZ QUESTION: :

Here's an example request:

GET http://www.example.com/tasks?term=homework HTTP/2.0
Accept-Language: en

See if you can match each element of the example with the appropriate component.

ANSWER CHOICES:



Component

Example Element

Not Included

Accept-Language

GET

http://www.example.com/tasks?term=homework

HTTP/2.0

SOLUTION:

Component

Example Element

Not Included

Accept-Language

GET

http://www.example.com/tasks?term=homework

HTTP/2.0

The client wants to modify just a part of the representation of a given resource. Which of the following request methods should they use?

SOLUTION: PATCH

QUIZ QUESTION: :

Match the request method to its description.

ANSWER CHOICES:



Description

Method

GET

PATCH

POST

DELETE

OPTIONS

PUT

SOLUTION:

Description

Method

GET

PATCH

POST

DELETE

OPTIONS

PUT